function createNegativeArrayProxy(array) {
  if (!Array.isArray(array)) {
    return new TypeError('不是数组类型');
  }
  return new Proxy(array, {
    get: (target, index) => {
      index = +index; // 相对巧妙的转类型
      return target[index < 0 ? target.length + index : index];
    },
    set: (target, index, value) => {
      index = +index;
      return (target[index < 0 ? target.length + index : index] = val);
    },
  });
}

const users = ['Jimmy', 'xuexue', 'Jack'];
let proxyUser = createNegativeArrayProxy(users);
console.log(users[-1]);
console.log(proxyUser[-1]);
